package com.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 配置MVCconfig
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer{
	//直接对某些请求的url做映射
		public void addViewControllers(ViewControllerRegistry registry) {
			registry.addViewController("/login.html").setViewName("login");
			registry.addViewController("/dog").setViewName("login");
			registry.addViewController("/cat/sheep").setViewName("login");
		}
		
		//添加拦截器
		public void addInterceptors(InterceptorRegistry registry) {
			registry.addInterceptor(new SessionInterceptor())
	 			.addPathPatterns("/**")
				.excludePathPatterns("/my-web-0.0.1/**","/login.html","/login","/"); 
		}
		
		@Bean
		WebMvcConfigurer WebMvcConfigurer() {
			return this; 
		}
}
